/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * InsertarPais.java
 *
 * Created on 21-sep-2011, 18:23:18
 */
package GUI;

/**
 *
 * @author Silvana
 */
import Data.Pais;
import MyLinkedList.LinkedList;
import javax.swing.JOptionPane;

public class InsertarPais extends javax.swing.JDialog {

    public static LinkedList paisesDevolver = new LinkedList();
   

    /** Creates new form InsertarPais */
    public InsertarPais(java.awt.Frame parent, boolean modal) {

        super(parent, modal);
        initComponents();

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jp = new javax.swing.JPanel();
        lblPais = new javax.swing.JLabel();
        lblContinente = new javax.swing.JLabel();
        cbContinente = new javax.swing.JComboBox();
        cbPais = new javax.swing.JComboBox();
        jbtnInsertar = new javax.swing.JButton();
        jbtnSalir = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Insertar País");

        lblPais.setText("País");

        lblContinente.setText("Continente");

        cbContinente.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Seleccione un Continente", "África", "América Central", "América del Norte", "América del Sur", "Europa", "Asia", "Oceanía", "Antártida" }));
        cbContinente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbContinenteActionPerformed(evt);
            }
        });

        cbPais.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Seleccione un País" }));
        cbPais.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbPaisActionPerformed(evt);
            }
        });

        jbtnInsertar.setText("Insertar");
        jbtnInsertar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnInsertarActionPerformed(evt);
            }
        });

        jbtnSalir.setText("Salir");
        jbtnSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnSalirActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jpLayout = new javax.swing.GroupLayout(jp);
        jp.setLayout(jpLayout);
        jpLayout.setHorizontalGroup(
            jpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpLayout.createSequentialGroup()
                .addGroup(jpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpLayout.createSequentialGroup()
                        .addGap(19, 19, 19)
                        .addGroup(jpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblContinente, javax.swing.GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE)
                            .addComponent(lblPais))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(cbPais, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(cbContinente, 0, 216, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jbtnInsertar)
                        .addGap(37, 37, 37)))
                .addComponent(jbtnSalir)
                .addContainerGap())
        );
        jpLayout.setVerticalGroup(
            jpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpLayout.createSequentialGroup()
                .addContainerGap(23, Short.MAX_VALUE)
                .addGroup(jpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblContinente, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbContinente, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblPais, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbPais, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbtnSalir)
                    .addComponent(jbtnInsertar))
                .addGap(7, 7, 7))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jbtnSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnSalirActionPerformed


        this.dispose();


    }//GEN-LAST:event_jbtnSalirActionPerformed

    public static LinkedList devolver(){
        return paisesDevolver;
    }
    private void cbContinenteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbContinenteActionPerformed

        int aux = this.cbContinente.getSelectedIndex();
        switch (aux) {
            //Africa
            case 1:
                cbPais.removeAllItems();
                String[] africa = {"Seleccione un País", "Angola", "Argelia", "Benín", "Botsuana", "Burkina Faso", "Burundi", "Cabo Verde", "Camerún",
                    "Chad", "Comoras", "Congo", "Costa de Marfil", "Yibuti", "Egipto", "Eritrea", "Etiopía", "Gabon", "Gambia",
                    "Ghana", "Guinea", "Guinea-Bissau", "Guinea Ecuatorial", "Kenia", "Lesoto", "Liberia", "Libia", "Madagascar",
                    "Malawi", "Malí", "Marruecos", "Mauricio", "Mauritania", "Mozambique", "Namibia", "Níger", "Nigeria", "República Centroafricana",
                    "República Democrática del Congo", "Ruanda", "Santo Tomé y Príncipe", "Senegal", "Seychelles", "Sierra Leona", "Somali",
                    "Sudáfrica", "Sudán", "Swazilandia", "Tanzania", "Togo", "Túnez", "Uganda", "Zambia", "Zimbabwe"};
                for (int i = 0; i < africa.length; i++) {
                    String aux2 = africa[i];
                    this.cbPais.addItem(aux2);
                }
                break;
            //America central
            case 2:
                cbPais.removeAllItems();
                String[] americaC = {"Seleccione un País", "Antigua y Barbuda", "Bahamas", "Barbados", "Bélice", "Costa Rica", "Cuba",
                    "Dominica", "El Salvador", "Granada", "Guatemala", "Haití", "Honduras", "Jamaica", "Nicaragua",
                    "Panamá", "Puerto Rico", "República Dominicana", "San Cristóbal y Nevis", "Santa Lucía", "San Vicente y las Granadinas",
                    "Trinidad y Tobago"};
                for (int i = 0; i < americaC.length; i++) {
                    String aux2 = americaC[i];
                    this.cbPais.addItem(aux2);
                }
                break;
            //America del Norte
            case 3:
                cbPais.removeAllItems();
                String[] americaN = {"Seleccione un País", "Canadá", "Estados Unidos", "México"};
                for (int i = 0; i < americaN.length; i++) {
                    String aux2 = americaN[i];
                    this.cbPais.addItem(aux2);
                }
                break;
            //America del Sur
            case 4:
                cbPais.removeAllItems();
                String[] americaS = {"Seleccione un País", "Argentina", "Bolivia", "Brasil", "Chile", "Colombia",
                    "Ecuador", "Guyana", "Paraguay", "Perú", "Surinam", "Uruguay", "Venezuela"};
                for (int i = 0; i < americaS.length; i++) {
                    String aux2 = americaS[i];
                    this.cbPais.addItem(aux2);
                }

                break;
            //Antartida
            case 5:
                cbPais.removeAllItems();
                String[] antartida = {"Seleccione un País", "Islas Georgias del Sur", "Islas Sandwich del Sur", "isla Bouvet",
                    "Islas Heard y McDonald"};
                for (int i = 0; i < antartida.length; i++) {
                    String aux2 = antartida[i];
                    this.cbPais.addItem(aux2);
                }

                break;
            //Asia
            case 6:
                cbPais.removeAllItems();
                String[] asia = {"Seleccione un País", "Abjasi", "Afganistán", "Alto-Karabaj", "Arabia Saudita",
                    "Armenia", "Azerbaiyán", "Baréin", "Bangladés", "Birmania",
                    "Bután", "Brunéi", "Camboya", "China", "Chipre", "Corea del Norte",
                    "Corea del Sur", "Emiratos Árabes Unidos", "Filipinas", "Georgia", "Indonesia",
                    "India", "Irán", "Irak", "Islas Cocos", "Isla de Navidad", "Israel", "Japón",
                    "Jordania", "Kazajistán", "Kirguistán", "Kuwait", "Laos", "Líbano", "Malasia",
                    "Maldivas", "Mongolia", "Nepal", "Norte de Chipre", "Omán", "Pakistán", "Palestina",
                    "Catar", "Rusia", "Singapur", "Siria", "Sri Lanka", "Tailandia", "Tayikistán",
                    "Terr. Brit. del Índico", "Timor Oriental", "Osetia del Sur", "Taiwán",
                    "Turkmenistán", "Turquía", "Uzbekistán", "Vietnam", "Yemen"};
                for (int i = 0; i < asia.length; i++) {
                    String aux2 = asia[i];
                    this.cbPais.addItem(aux2);
                }
                break;
            //Europa
            case 7:
                cbPais.removeAllItems();
                String[] europa = {"Seleccione un País", "Albania", "Alemania", "Andorra", "Armenia", "Austria", "Azerbaiyán",
                    "Bélgica", "Bielorrusia", "Bosnia y Herzegovina", "Bulgaria", "Chipre", "Ciudad del Vaticano",
                    "Croacia", "Dinamarca", "Escocia", "Eslovaquia", "Eslovenia", "España", "Estonia", "Federación rusa",
                    "Finlandia", "Francia", "Georgia", "Gran Bretaña (Reino Unido)", "Grecia", "Hungría", "Irlanda",
                    "Islandia", "Italia", "Letonia", "Liechtenstein", "Lituania", "Luxemburgo", "Macedonia",
                    "Malta", "Moldavia", "Mónaco", "Noruega", "Países Bajos", "Polonia", "Portugal", "República Checa",
                    "Rumania", "San Marino", "Suecia", "Suiza", "Turquía", "Ucrania", "Serbia y Montenegro"};
                for (int i = 0; i < europa.length; i++) {
                    String aux2 = europa[i];
                    this.cbPais.addItem(aux2);
                }
                break;
            //Oceania 
            case 8:
                cbPais.removeAllItems();
                String[] oceania = {"Seleccione un País", "Australia", "Fiji", "Isla Norfolk", "Islas Ashmore y Cartier",
                    "Islas Christmas", "Islas Cook", "Islas Marshall", "Islas Pitcairn", "Islas Salomón",
                    "Islas de Heard y McDonald", "Islas del Mar del Coral", "Kiribati", "icronesia",
                    "Nauru", "Niue", "Nueva Caledonia", "Nueva Zelanda", "Palau", "Papúa Nueva Guinéa",
                    "Polinesia Francesa", "Samoa", "Tokelau", "Tonga", "Tuvalu", "Vanuatu", "Wallis y Futuna"};
                for (int i = 0; i < oceania.length; i++) {
                    String aux2 = oceania[i];
                    this.cbPais.addItem(aux2);
                }
                break;


        }










    }//GEN-LAST:event_cbContinenteActionPerformed

    private void cbPaisActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbPaisActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cbPaisActionPerformed

    private void jbtnInsertarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnInsertarActionPerformed


        if (cbContinente.getSelectedIndex() == 0 || cbPais.getSelectedIndex() == 0) {
            JOptionPane.showMessageDialog(this, "Seleccione antes un continente y un pais, por favor..");
            return;
        }
        int itemPais = cbPais.getSelectedIndex();
        Pais p = new Pais((String) cbPais.getSelectedItem(), cbContinente.getSelectedIndex());
        //cbPais.remove(itemPais);
        if (paisesDevolver.add(p)) {
            JOptionPane.showMessageDialog(null, "Pais insertado correctamente.");
            this.limpiarCombo();
        }

        // TODO add your handling code here:
    }//GEN-LAST:event_jbtnInsertarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(InsertarPais.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(InsertarPais.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(InsertarPais.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(InsertarPais.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                InsertarPais dialog = new InsertarPais(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox cbContinente;
    private javax.swing.JComboBox cbPais;
    private javax.swing.JButton jbtnInsertar;
    private javax.swing.JButton jbtnSalir;
    private javax.swing.JPanel jp;
    private javax.swing.JLabel lblContinente;
    private javax.swing.JLabel lblPais;
    // End of variables declaration//GEN-END:variables

    public void limpiarCombo() {
        String[] continente = {"Seleccione un Continente", "África", "América Central", "América del Norte", "América del Sur", "Antártida", "Asia", "Europa", "Oceanía"};
        this.cbContinente.removeAllItems();
        for (int i = 0; i < continente.length; i++) {
            String aux2 = continente[i];
            this.cbContinente.addItem(aux2);
        }
        this.cbPais.removeAllItems();
        this.cbPais.addItem("Seleccione un País");
    }

    public static void insertarPaises() {
        paisesDevolver.clear();
        InsertarPais p = new InsertarPais(null, true);
        p.setVisible(true);
    }
}
